package pers.course.week9;

import java.util.*;

public class TelephoneDictionary {
    public static char[] key;
    public static void init() {
        key = new char[256];
        key['A'] = key['B'] = key['C'] = '2';
        key['D'] = key['E'] = key['F'] = '3';
        key['G'] = key['H'] = key['I'] = '4';
        key['J'] = key['K'] = key['L'] = '5';
        key['M'] = key['N'] = key['O'] = '6';
        key['P'] = key['R'] = key['S'] = '7';
        key['T'] = key['U'] = key['V'] = '8';
        key['W'] = key['X'] = key['Y'] = '9';
    }
    public static void main(String[] args) {
        init();
        Scanner cin = new Scanner(System.in);
        Map<String, Integer> tm = new TreeMap<String, Integer>();
        int total = cin.nextInt();
        String ts;
        int i, j;
        cin.nextLine();
        for (i = 0; i < total; i++) {
            ts = cin.nextLine().replace("-", "");
            StringBuilder sb = new StringBuilder();
            for (j = 0; j < ts.length(); ++j) {
                if (Character.isDigit(ts.charAt(j))) {
                    // 数字直接写入
                    sb.append(ts.charAt(j));
                } else {
                    // 字母转换为数字后写入
                    sb.append(key[ts.charAt(j)]);
                }
            }
            //电话号格式标准化
            String result = sb.toString().substring(0, 3) + "-" + sb.toString().substring(3);
            if (tm.containsKey(result)) {
                int count = tm.get(result) + 1;
                tm.put(result, count);
            } else {
                tm.put(result, 1);
            }
        }
        Set<String> st = tm.keySet();
        for (String s : st) {
            String ss = s.toString();
            int count = tm.get(ss);
            if (count > 1) {
                System.out.println(ss + " " + count);
            }
        }
    }
}
